<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/html/axios.min.js"></script>
<script src="/html/util.js"></script>

<script>
    window.onload = function (){
        showUser();
        showChannel();
    }

    function showUser(){
        axios.get("/user/getUser",null).then( e=> {
            var userObj = e.data;
            if (userObj == null || userObj== ''){
                $('userName').innerHTML = "请先<a href='/html/login.html'>登录</a>"
            }
            $('face').src = "/html/img/"+userObj.face;
            $('mailSpan').innerHTML = "邮箱:"+userObj.mail;
            $('codeSpan').innerHTML = "登录用户:"+userObj.code;
        })
    }
    function showChannel(){
        axios.get("/channel/getChannel",null).then( e=> {
            var channelList = e.data;
            var str = "";
            for (var i=0;i<channelList.length;i++){
                var obj = channelList[i];
                str += `<tr><td><a href="/html/topic.html?id=${obj.id}">${obj.name}</a></td>
                        <td>${obj.describe}</td><td>${obj.count}</td></tr>`
            }
            $('channelData').innerHTML = str;
        })
    }

</script>
<body>
    <h3>欢迎你</h3>
    <span id="userName"></span><br>
    <div>
        <img id="face" style="width: 50px" height="50px"><br>
        <span id="codeSpan"></span><br>
        <span id="mailSpan"></span>
    </div>
    <table width="60%" cellspacing="0">
        <thead>
            <tr><th>频道名称</th><th>频道描述</th><th>主贴数量</th></tr>
        </thead>
        <tbody id="channelData"></tbody>
    </table>
</body>
</html>